<?php
/**
 * Created by PhpStorm.
 * User: yzapple
 * Date: 2018/1/10
 * Time: 上午9:44
 */
namespace app\common\model;
use app\common\model\Base;
use think\Db;
class PatientCaseType extends Base
{

    protected $table = "patient_case_type";

    public $base_arr = [
        'table' => 'patient_case_type',
        'field' => 'name,type,doctor_id',
        'primary_key' => 'id'
    ];

    public $attach_arr = [
        [
            'table' => 'doctor',
            'field' => 'name',
            'primary_key' => 'id',
            'base_table_field' => 'doctor_id'
        ],



    ];

    /**
     * 获取字段对应的数组
     * */
    public function getDataByMysql(){
        $data = [
            't_name' => $this->table,//必填
            'model' => '病例类型',//必填
            'name' => '名称',
            'doctor_id' => '录入医生',
            'type' => '{"1":"检查类型","2":"检查部位","3":"检查纬度"}',
            'is_deleted' => '{"2":"功能禁用","1":"功能启用","3":"功能删除"}'
        ];
        return $data;
    }


    /**
     * 获取日志的访问方法
     **/
    public static function getPatientCaseTypeAdminLog($list_action = '', $form_data = [], $userId, $admin_type)
    {
        $model = new Doctor();
        $actionName = strtolower(ACTION_NAME);
        $controller = strtolower(CONTROLLER_NAME);
        $old_data = [];
        $type = '';

        switch ($actionName) {
            //列表
            case "index":
                Base::save_admin_log($userId, $model, 'check','',[],[],$admin_type);
                break;
            case "add_type":
                if ($model->request->isPost()) {
                    $form_data['doctor_id'] = $userId;
                }

                break;
            case "del":
                $type = 'del';
                if ($model->request->isPost()) {
                    $id = $form_data["id"];
                    Db::execute("update patient_case_type set is_deleted=3  where id=?", [ $id]);

                }
                break;
        }


        if ($model->request->isPost()) {

            //$model 实例化之后的模型
            //$type 数据的操作类型
            //$form_data  form表单提交之后的表单
            //$url 跳转路径
            //$old_data 原有的数据
            //$attach_arr 附属表单数组
            //$primary_key 基本表单的主键值id
            $result = Base::operaTable($model, $userId, $type, $form_data, $controller . '/' . $list_action, $old_data, $model->attach_arr, 'id', $admin_type);
            return $result;
        }


        return true;


    }


}